package y24.m3;

public class Test17 {
    static class TreeNode{
        private int val;
        private TreeNode left;

        public TreeNode() {
        }

        private TreeNode right;
        public TreeNode(int val){
            this.val = val;
        }
    }
    static class Solution {
        public static int maxDepth(TreeNode root) {
            if (root == null){
                return 0;
            }
            int leftHeight = maxDepth(root.left);
            int rightHeight = maxDepth(root.right);
            return Math.max(leftHeight,rightHeight) + 1;
        }
    }
    public static TreeNode createTreeOne(){
        TreeNode A = new TreeNode(3);
        TreeNode B = new TreeNode(9);
        TreeNode C = new TreeNode(20);
        TreeNode D = new TreeNode(15);
        TreeNode E = new TreeNode(7);
        A.left = B;
        A.right = C;
        C.left = D;
        C.right = E;
        return A;
    }

    public static void main(String[] args) {
        TreeNode root = createTreeOne();
        System.out.println(Solution.maxDepth(root));
    }
}
